nginx屏蔽指定接口(URL)的操作方式 | 您所在的位置:网站首页 › 前端 nginx 被屏蔽 › nginx屏蔽指定接口(URL)的操作方式 |
一、前言 有时候,web平台上线后,需要屏蔽某个服务接口,但又不想重新上线,可以采用nginx屏蔽指定平台接口的办法。 二、具体操作 在nginx的配置文件nginx.conf文件的server节点中,添加一个location,示例如下: location /your url { return 403;}三、事例一 以nginx反向代理某个服务为例,禁止访问http://IP:8080/nn123/ser链接页面 location /nn123/ser/ { index index.html index.htm index.jsp; proxy_pass http://192.4.30.24:8080/nn123/ser/; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host:$server_port; return 403; }四、事例二 Nginx禁止访问特定url,以go-fastdfs中pprof页面暴露例,前提是go-fastdfs是以nginx代理出去访问(组名),才可以禁止访问“http://IP:端口/debug/pprof/“页面的 nginx添加如下内容禁止访问pprof页面 location = /debug/pprof/ { return 404; }五、事例三 这里具体以nginx自带nginx.conf为例,屏蔽根URL路径/: 1、屏蔽前 location / { root html; index index.html index.htm;}访问nginx index.html页面结果如下: 2、屏蔽后 location / { return 403; root html; index index.html index.htm;}访问nginx index.html页面结果如下: 修改完nginx.conf配置文件后,不用重启nginx,执行命令nginx -s reload|systemctl reload nginx重新加载配置文件,修改的规则即可生效。 |
CopyRight 2018-2019 实验室设备网 版权所有 |